home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.comet.net!not-for-mail
- From: mwilliams1@comet.net
- Subject: Re: The size of a file
- Message-ID: <11a7cc$142013.177@news.comet.net>
- Date: Sat, 27 Jan 1996 01:32:19 GMT
- Reply-To: mwilliams1@comet.net
- References: <4ebc03$4gv@gate.compart.fi>
- X-Newsreader: IBM NewsReader/2 v1.2.5
-
- In <4ebc03$4gv@gate.compart.fi>, Fredrik Sandstrom <fred@spider.compart.fi> writes:
- >This is driving me nuts. I can't find a simple way to get the size of a
- >disk file. This must be possible using the standard C library, but I
- >haven't figured out how!
-
- #include <stdio.h>
-
- int main(int argc, char *argv[]) {
- FILE *fptr;
- fpos_t length;
- fptr=fopen(argv[1],"r");
- if (fptr==NULL) {
- printf("Argh! Can't open '%s' !\n",argv[1]);
- exit(-1);
- }
- fseek(fptr,0,2);
- length=ftell(fptr);
- printf("The size of '%s' is %ld bytes\n",argv[1],length);
- fclose(fptr);
- return(0);
- }
-
-
-
- -Mike Williams
-
-
-